package com.zdgcc.site.util;

import java.io.File;
import java.util.List;

import org.apache.commons.fileupload.FileItem;

public class UploadFile {

	public boolean uploadFile(String uploadPath, long maxSize, List<FileItem> items, List<String> fileNames) {
		boolean flag = false;
		File uploadFile = new File(uploadPath);
		if (!uploadFile.exists()) {
			uploadFile.mkdirs();
		}

		for (int i = 0; i < items.size(); i++) {
			FileItem fi = items.get(i);
			if (!fi.isFormField()) {
				String fileName = fileNames.get(i);
				if (fileName != null && !"".endsWith(fileName)) {
					File savedFile = new File(uploadPath, fileName);
					try {
						fi.write(savedFile);
						flag = true;
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
		return flag;
	}
}
